perm filename WORD[E,ALS] blob sn#186823 filedate 1975-11-20 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00002 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	Code to extract one or more words from a line of text as specified by
C00007 ENDMK
C⊗;
;Code to extract one or more words from a line of text as specified by
;an argument with the command αβ∨.

	movem a,sarg
	pushj p,parsav			;Use the save mechanism from Paren
	HRRZ E,ARRLIN
	MOVEI H,LLDESC(E)
	TLO H,440700
	MOVE D,[440700,,BUF]
	TRNN F,EDITM
	JRST WORD2
	MOVE B,EDCNM
	MOVE Q,EDPOS
	ADD Q,EDTBS
	ADD Q,EDTBS
	JUMPE Q,WORD3
WORD0:	ILDB C,H
	CAIE C,40
	CAIN C,14
	JRST [MOVEM H,HSAV
	      MOVEM D,DSAV
	      JRST WORD1]
WORD1:	IDPB C.D
	SOJG Q,WORD0
	MOVEM C,CSAV			;Save character at cursor position
	MOVE H,HSAV			;Back up to the last delimiter
	MOVE D,DSAVE



;Now put selected words into the ATTACH buffer
	ILDB C,H
	CAIE C,40
	CAIN C,14

;Now continue with rest of the line
WORD5:	ILDB C,H
	IDPB C,D
	CAIE C,15			;Go to the end of the line
	JRST WORD5
	MOVEI C,12
	IDPB C,D
	MOVEI C,0
	IDPB C,D			;Terminate with a null
	TLNE D,760000
	JRST .-2			;Pad out to end of word

;This code lifted from JDFIN. It will have to be modified but then it may
;be possible to write it as a subroutine that both JDFIN and this code call.
	AOS @JLPTR(E)			;Add 1 to value in LINES or ATTNUM
	ADDI G,2(B)			;Increase G by 2 + # of characters
	ADDM G,@JCPTR(E)		;Add this to value in CHARS or ATTSIZ.
	LSH G,11			;Move G to byte position.
	IORI G,(B)			;IOR in the actual char count.
	MOVEI B,-BUF2+1+LLDESC(A)	;Number of words.
	PUSHJ P,FSGET			;Get space to store line.
	MOVSI TT,BUF2			;Starting location of source
	HRRI TT,LLDESC(A)		;and starting location of destination.
	BLT TT,-2(T)			;and now BLT, ending at location -2(T)
	MOVSI T,TXTCOD			;A fancy way to store 2 in left half!
	HLLM T,-1(A)			;To 1st header word.
	HRRZM G,1(A)			;Char. cnts in right of 3rd header word.
	AOS T,TXTNUM
	MOVEM T,2(A)			;To 4th header word.
	HLRZ T,JLPT
	CAIE T,PAGE
	SKIPGE 1(T)
	TRO F,UPDTXT			;Flag change in first line.
	HRLI T,JLPT
	MOVSM T,(A)
	HRRM A,(T)
	HRLZM A,JLPT
	MOVE A,D
	MOVE D,[440700,,BUF]
	MOVEM D,JWPT
	SETZM JWCOL
	POP P,C
	TDZA B,B		;Tricky way to set to zero and skip.
	ILDB C,A
	CAIN C,40		;Is there a superfluous CR?
	JRST .-2		;Yes.
	JUMPE C,JDFIN2
	IDPB C,D		;Put unused part back into BUF.
	ILDB C,A
	AOBJP B,.-3
	JRST JDFIN2

;JDFIN2, JSET, JSET2

        ;We enter at JDFIN2 from end of JBFIN or from 4 lines earlier if C is NULL.
JDFIN2:	POP P,A
        ;We enter at JSET from JUST only. This is before BUF is loaded.
JSET:	MOVN T,LMAR
        ;We enter at JSET2 from NXTBL which in turn is entered from LXTLN2
        ;  if T LAND 777 =0 which means the start of a block.
;Note:the next two instructions ane new oct.23,74.
JSET2:	MOVNM T,TMPMAR		;We arrive here with - the correct margin in T
	ADD T,RMAR
JSET4:	ADDI T,1
	TLNE F,INDEN!CEN!ALIN!JOINF	;Test for non-filling flags
	MOVE T,JSIZE2
	MOVEM T,JSIZE#
	MOVSI T,(T)
	SUB B,T
	SETZM JSCNT#
	MOVSI H,LSPC
	MOVEI DSP,JDISP		;Used only for JUST and JFILL
	TLNE F,CEN
	MOVEI DSP,JNDISP	;Special dispatch table for this case
	TLNE F,INDEN!ALIN
	MOVEI DSP,JADISP	;Special dispatch table for these cases
	POPJ P,